use yew::{function_component, html, use_state, Html, Properties};
use yew_hooks::{use_interval, use_mount};
use crate::business::app_state::AppState;
use crate::business::websocket::dto::ping_dto::PingReq;
use crate::business::websocket::receive_send_handle::ImReceiveSendHandleMsg;

#[derive(Properties, PartialEq, Clone)]
pub struct HeartCheckProps {
    pub interval_time: u32,
}

#[function_component(HeartCheck)]
pub fn heart_check(props: &HeartCheckProps) -> Html {
    let app_state = use_state(|| { AppState::new() });

    let receive_send_data = app_state.receive_send_handle.clone();
    let interval_time = props.interval_time;
    use_mount(move || {
        use_interval(move || {
            if let Some(receive_send_data) = receive_send_data.as_ref() {
                log::info!("begin heart check");
                receive_send_data.dispatch(ImReceiveSendHandleMsg::Ping(PingReq::default()));
            }
        }, interval_time);
    });
    html! {
        
    }
}